package cc.dullsky.category;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.core.Controller;

import cc.dullsky.common.model.ArticleCategory;
import cc.dullsky.common.model.Category;

public class CategoryController extends Controller {
	/**
	 * ajax获取头部导航栏
	 */
	public void getNav() {
		renderJson(Category.dao.findAll());
	}

	/**
	 * ajax获取侧边分类目录
	 */
	public void getSideCategory() {
		List<Category> categories = Category.dao.findFirstCategory();
		List<Map<String, Object>> list = new ArrayList<>();
		for (Category category : categories) {
			Map<String, Object> map = new HashMap<>();
			map.put("id", category.getId());
			map.put("name", category.getName());
			map.put("count", ArticleCategory.dao.countByCategoryId(category.getId()));
			list.add(map);
		}
		renderJson(list);
	}
}
